cat('\n\nCreating Table A33\n\n')

dat = read.csv('TableA33_data.csv')

black.dat = dat[dat$black == 1,]
hisp.dat = dat[dat$black == 0,]

black.sets = quantile(black.dat$turndiff,c(.25,.75))
hisp.sets = quantile(hisp.dat$turndiff,c(.25,.75))

black = black.dat[black.dat$turndiff >= black.sets[1]&black.dat$turndiff <= black.sets[2],]
hisp = hisp.dat[hisp.dat$turndiff >= hisp.sets[1]&hisp.dat$turndiff <= hisp.sets[2],]

usedata = list(black,hisp)

form = "junevote~
difftreat+
sametreat+
distance+
compare.block.herf+
vote.history+dem+rep+age"


results = matrix(nrow = 12, ncol = 2)

for(i in 1:length(usedata)){
		fm  <- lm(as.formula(form),
			data=usedata[[i]],
		      	  x=T,y=T)
		output <-  cl(dat=usedata[[i]],
	            fm,cluster = usedata[[i]]$cityblock)
	         ##test for difference in coefficients, using robust vcov
	     	coef.comparison = linearHypothesis(fm,
	     		"difftreat = sametreat",
	     		vcov = output$vcov)

   	results[1,i] = output$coefficients['(Intercept)',1]
   	results[2,i] = output$coefficients['(Intercept)',2]
 		results[3,i] = output$coefficients['difftreat',1]
		results[4,i] = output$coefficients['difftreat',2]
		results[5,i] = output$coefficients['sametreat',1]
		results[6,i] = output$coefficients['sametreat',2]
		results[7,i] = nrow(usedata[[i]])			
		results[8,i] = summary(fm)$r.squared
		results[9,i] = summary(fm)$adj.r.squared
		results[10,i] = sd(summary(fm)$residuals)
		results[11,i] = output$coefficients['difftreat',1] - output$coefficients['sametreat',1]
		results[12,i] = coef.comparison$F[2]
		}


results = round(results,2)
results[c(2,4,6),] = paste('(',results[c(2,4,6),],')',sep='')
rownames(results) = c('intercept','intercept.se','difftreat','diffterat.se', 'sametreat','sametreat.se','N','r.squared','adj.r.squared','resid.sd','diff.same','diff.same.f')
colnames(results) = c('black','hispanic')


out.results = xtable(results, digits = 2)
print.xtable(out.results, 
	file = 'TableA33.tex',
	booktabs = T
	)		


